package sanrenxing.dayEnd.backRepertoryTotal.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import sanrenxing.dayEnd.backRepertoryTotal.dao.FundAllocationDao;
import sanrenxing.dayEnd.backRepertoryTotal.domain.CashReceivable;
import sanrenxing.dayEnd.backRepertoryTotal.domain.FundAllocation;
import sanrenxing.dayEnd.backRepertoryTotal.service.FundAllocationBiz;

import java.util.List;

/**
 * @ClassName:资金调拨业务层
 * @description:孙祥兵
 * @date:2021/3/13 9:50
 * @version:1.0
 **/
@Service("/FundAllocationBiz")
public class FundAllocationServiceImpl implements FundAllocationBiz {
    @Autowired
    private FundAllocationDao fundAllocationDao;
    /**
     * 将调拨实体类添加到数据库表中
     *
     * @param fundAllocation 调拔对象
     * @return 0：增加成功，1：增加失败
     */
    @Override
    public int add(FundAllocation fundAllocation) {
        return fundAllocationDao.add( fundAllocation);
    }


    /**
     * 从表中按照编号删除一行数据
     *
     * @param tofId 调拔编号
     * @return 0：删除成功，1：删除失败
     */
    @Override
    public int delete(int tofId) {
        return fundAllocationDao.delete(tofId);
    }

    /**
     * 修改一行数据
     *
     * @param fundAllocation 调拔对象
     * @return 0：修改成功，1：修改失败
     */
    @Override
    public int update(FundAllocation fundAllocation) {
        return fundAllocationDao.update(fundAllocation);
    }

    /**
     * 按条件分页查询
     *
     * @param rows 行数
     * @param pages 页数
     * @param condition 条件
     * @return 调拔集合
     */
    @Override
    public List<FundAllocation> findAll(int rows, int pages, String condition) {
        int start=(pages-1)*rows;
        int row=pages*rows+1;
        return fundAllocationDao.findAll(start,row,condition);
    }



    /**
     * 按条件统计记录数
     *
     * @param condition 统计的条件
     * @return 记录的行数
     */
    @Override
    public int count(String condition) {
        return fundAllocationDao.count(condition);
    }

    /**
     * 获取查询条件
     *
     * @param fundAllocation 调拔对象
     * @return 字符串集合
     */
    @Override
    public String getCondition(FundAllocation fundAllocation) {
        //定义查询条件字符串，初值为带空格的字符串
        String condition=" ";
        //如果调拨对象为空
        if (fundAllocation==null){
            return condition;
        }


        //如果调拨编号不为0
        if (fundAllocation.getTofId()!=0){
            condition+=" and tofId="+fundAllocation.getTofId();
        }
        //如果基金编号不为空
        if (fundAllocation.getFundId()!=null && fundAllocation.getFundId().trim().length()!=0){
            condition +=" and fundId like '%"+fundAllocation.getFundId()+"%' ";
        }
        //如果现金编号不为0
        if (fundAllocation.getCaId()!=0){
            condition+=" and caId="+fundAllocation.getCaId();
        }
        //如果调拨类型不为空
        if (fundAllocation.getReType()!=null && fundAllocation.getReType().trim().length() != 0){
            condition +=" and reType like '%"+fundAllocation.getReType()+"%' ";
        }
        //如果调拨金额不为0
        if (fundAllocation.getReMoney()!=0){
            condition+=" and reMoney="+fundAllocation.getReMoney();
        }
        //如果资金流动方向不为0
        if(fundAllocation.getDial()!=0){
            condition+=" and dial="+fundAllocation.getDial();
        }
        return condition;
    }

    /**
     * 添加现金应收应付数据
     * @param cashReceivable
     */
    @Override
    public void addSec(CashReceivable cashReceivable) {
        //调用添加现金应收应付方法
        fundAllocationDao.addSec(cashReceivable);
    }
}
